# -*- coding: utf-8 -*-
# created by Src - 一路好时光

f = open('w-test.txt')
#读时用seek
# f.seek(6)#把光标移动到6字节处
# print(f.readline())#world   ---hello world

# print(f.seek(14))  #把中文截断了，报错，字符读取错误
# print(f.readline())
#hello world
#张三

#报错内容
#     print(f.readline())
#           ^^^^^^^^^^^^
# UnicodeDecodeError: 'gbk' codec can't decode byte 0xfd in position 2: illegal multibyte sequence
f.close()

#写时用seek
f=open("seek-write.txt","w")
f.write("hellosrc1\n")
f.write("hellosrc2\n")
f.write("hellosrc3\n")
f.write("hellosrc4\n")
f.seek(13)
f.write("ddddddddddd")
# hellosrc1
# hedddddddddddllosrc3
# hellosrc4

print(f.tell())#返回光标位置

f.flush()#把内存buffer数据刷新到磁盘
f.close()

#以下在终端操作
f=open("file_flush.txt","w")
f.write("line1\n")
f.write("line2\n")
f.flush()
